package com.mfin.bs.mgr.impl;

import com.mfin.bom.factory.UserInformationFactory;
import com.mfin.bom.factory.interfaces.IUserInformationFactory;
import com.mfin.bom.interfaces.IFinance;
import com.mfin.bom.interfaces.IUser;
import com.mfin.bs.mgr.interfaces.IUserProfileManager;
import com.mfin.vo.UserVO;
import com.mfin.vo.finance.FinanceVO;

public class UserProfileManager extends BaseManager implements
		IUserProfileManager {

	IUserInformationFactory userInformationFactory = new UserInformationFactory();

	@Override
	public UserVO validateUser(UserVO userVO) {
		logMethodBegin("UserProfileManager", "validateUser");

		userInformationFactory.setPersistenceGovernor(getPersistenceGovernor());
		IUser bomUser = userInformationFactory.getUserInformation(userVO
				.getUserId().toUpperCase());

		UserVO validatedUserVO = null;
		if (bomUser != null
				&& bomUser.getPassword().equals(userVO.getPassword())) {
			validatedUserVO = new UserVO();

			map(bomUser, validatedUserVO, false, true);
		}

		logMethodEnd("UserProfileManager", "validateUser");
		return validatedUserVO;
	}

	@Override
	public FinanceVO getUserFinance(UserVO userVO) {
		logMethodBegin("UserProfileManager", "getUserFinance");

		userInformationFactory.setPersistenceGovernor(getPersistenceGovernor());
		IUser bomUser = userInformationFactory.getUserInformation(userVO);

		FinanceVO financeVO = null;
		IFinance bomFinance = bomUser.getFinance();
		if (bomUser != null && bomFinance != null) {
			financeVO = new FinanceVO();
			map(bomFinance, financeVO, false, true);
		}

		logMethodEnd("UserProfileManager", "getUserFinance");
		return financeVO;
	}

}
